package run;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.List;
@Slf4j
@SpringBootTest(classes = {ActivitiDemo.Dummy.class})
public class ActivitiDemo {
    @Autowired
    ProcessEngine processEngine ;
    @Autowired
    ProcessEngineConfiguration processEngineConfiguration;
    @Configuration
    public static class Dummy{}

    @BeforeEach
    public void setUp(){
         processEngine = processEngineConfiguration.buildProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment().addClasspathResource("processes/vacationRequest.bpmn20.xml").deploy();
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
        ProcessDefinition processDefinition = list.get(0);
        log.info("{}",processDefinition.getId(),processDefinition.getDiagramResourceName());


    }
    @Test
    public void load(){

        HashMap<String, Object> variables = new HashMap<>() {{
            put("employeeName", "john");
            put("numberOfDays",3L);
//            put("startDate", ); // MM-dd-yyyy hh:mm
            put("reason","i need a break");
        }};
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance vacationRequest = runtimeService.startProcessInstanceById("vacationRequest", variables);
        long count = runtimeService.createProcessInstanceQuery().count();
        Assertions.assertEquals(1L,1);;

    }
}
